package moreApi.src.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 使用正则表达式爬取信息
 */
public class RegexDemo4 {
    public static void main(String[] args) {
        String s = "来黑马学习java,#电话020-23434,或者联系邮箱" +
                "itcase@werfs.cn,电话18777772222,02023442222" +
                "邮箱bozao@fsdf.cn,400-100-3224,4003233333";
        //爬取出电话号码和邮箱
        //1.定义字符串形式爬取规则
        String regex = "(1[3-9]\\d{9})|([\\w&&[^_]]+@[\\w&&[^_]]+(\\.[\\w&&[^_]]+){1,2})";

        //2.把爬取规则编译成匹配对象
        Pattern pa = Pattern.compile(regex);

        //3.用匹配规则获得一个匹配器对象
        Matcher matcher = pa.matcher(s);

        //4.开始查找
        while(matcher.find()){
            String s1 = matcher.group();
            System.out.println(s1);
        }
    }
}
